Field of the Invention
The present invention relates to an image processing apparatus and an image processing method, and in particular to a technique to detect a motion vector between a plurality of images.
Description of the Related Art
In order to apply an anti-shake process to an image that has been captured using an image capture apparatus such as a digital still camera and a digital video camera, it is necessary to perform alignment by detecting a moving amount between a plurality of images (for example, frame images of a video). A moving amount between images is detected in various ways, e.g., by using information of an external device such as a gyroscope, and by way of estimation from the images.
A representative method for estimating a moving amount from images is to detect a motion vector through template matching. In template matching, one of two arbitrary images is used as a source image, and the other is used as a reference image. Correlation values (for example, distribution of luminance values) between a rectangular area (template block) of a predetermined size in the source image and a rectangular area in the reference image are obtained while changing the position of the template block. The position of the template block that yields a maximum correlation value is regarded as a move destination in the reference image, and a direction and an amount of movement from the position of the template block in the source image to the move destination are detected as a motion vector. With use of a motion vector obtained in the above-described manner, an anti-shake process, a moving object tracking process, and the like can be applied to an input image.
Template matching is a process to search the reference image for an area that has a high degree of similarity to the template block in terms of texture. Therefore, for example, in a case where the texture of the template block is a part of a repeating pattern or has low contrast, it is highly likely that the reference image includes a plurality of areas that have similar textures. In this case, there are a plurality of template block positions that yield large correlation values, and it becomes difficult to identify a position that serves as a true move destination; therefore, the possibility of failing to obtain a correct motion vector is increased (the reliability of a motion vector is reduced).
In view of this, Japanese Patent Laid-Open No. 2009-219082 suggests that whether or not the texture of a template block has a high possibility of failing to yield a correct motion vector (hereinafter referred to as a difficult area) be determined by analyzing the texture. An image processing apparatus described in Japanese Patent Laid-Open No. 2009-219082 detects a maximum correlation value and a local maximum of other correlation values, and determines whether or not the template block is a difficult area (whether or not the reliability of a motion vector detected using that template block is low) by comparing the maximum correlation value with the local maximum.
However, the image capture apparatus described in Japanese Patent Laid-Open No. 2009-219082 determines whether or not the template block is a difficult area based only on a magnitude relation between the maximum value and the local maximum among the correlation values, and does not consider a positional relation therebetween. Even if the template block is not a difficult area, it is not uncommon to obtain a correlation value that is close to the maximum correlation value in the neighborhood of a position that yields the maximum correlation value. It is thus difficult to determine the reliability of a detected motion vector with high accuracy only from a magnitude relation between the maximum value and the local maximum.